package com.datas.controller;

import com.datas.beans.ActResult;
import com.datas.service.InitProvinceService;
import com.datas.service.InitService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by jige0727 on 2017/5/28.
 * 初始化
 */
@Controller
public class InitController {
    @Autowired
    InitService initService;
    @Autowired
    InitProvinceService initProvinceService;

    @ResponseBody
    @RequestMapping(value = "/init", produces = "application/json;charset=UTF-8")
    public String init() {
        initService.initHQ();
        initService.initAdmin();
        initService.initUsers();
        initService.initPageResources();
        initService.initCountry();
        initProvinceService.initTown();
        return new ActResult(1, "ok").toJSONString();
    }

    @ResponseBody
    @RequestMapping(value = "/init2", produces = "application/json;charset=UTF-8")
    public String init2() {
        try {
            initService.initDepartments();
        } catch (Exception e) {
            LoggerFactory.getLogger(getClass()).error("error -> ", e);
        }
        return new ActResult(1, "ok").toJSONString();
    }

}
